import { Token } from "../ch2";

class ParserTree {
    // 子节点数组
    public children:ParserTree[] = [];

    /**
     * 添加规则节点 对应语法解析器
     * @param value 
     */
    addRuleNodeChild(value:string){
        let r = new RuleNode(value);
        this.children.push(r);
    }

    /**
     * 添加叶子节点 对应词法解析器
     * @param value 
     */
    addTokenNodeChild(value:Token){
        let t = new TokenNode(value);
        this.children.push(t);
    }
}

class RuleNode extends ParserTree {
    name:string;
    constructor(name:string){
        super();
        this.name = name;
    }
}

class TokenNode extends ParserTree{
    token:Token;
    constructor(token:Token) {
        super();
        this.token = token;
    }
    
}

export {
    ParserTree,
    RuleNode,
    TokenNode
}